package com.kotle.mvvmdesign.simpledemo;

import android.arch.lifecycle.Observer;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.kotle.baselib.mvvm.BaseMvvmActivity;
import com.kotle.mvvmdesign.R;
import com.kotle.mvvmdesign.databinding.ActivityMainBinding;


public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBinding> {

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_main;
    }

    @Override
    protected void onObserve(MainViewModel viewModel) {
        viewModel.adapter.observe(this, new Observer<RecyclerView.Adapter>() {
            @Override
            public void onChanged(@Nullable RecyclerView.Adapter adapter) {
                setRcvJokAdapter(adapter);
            }
        });
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initRcvJok();
        getViewModel().getJokList();

    }

    private void initRcvJok() {
        getBinding().rcvJok.setLayoutManager(new LinearLayoutManager(this));

    }

    void setRcvJokAdapter(RecyclerView.Adapter adapter) {
        getBinding().rcvJok.setAdapter(adapter);
    }

}
